package cn.shengongying.admin.controller;

import cn.shengongying.admin.dto.CompanyCardInDTO;
import cn.shengongying.bean.DataTablePageResult;
import cn.shengongying.bean.ResponseResult;
import cn.shengongying.model.BossCompanyCard;
import cn.shengongying.service.IBossCompanyCardService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * author: RXK
 * date: 2022/2/10 星期四
 * desc:
 */
@Controller
@RequestMapping("/sys/company/card")
public class CompanyCardController extends BaseController{


    private final IBossCompanyCardService companyCardService;

    public CompanyCardController(IBossCompanyCardService companyCardService) {
        this.companyCardService = companyCardService;
    }

    @RequestMapping("/index")
    public String index() {
        return "/company_card/index";
    }


    @ResponseBody
    @RequestMapping("/list")
    public DataTablePageResult<List<BossCompanyCard>> list(@RequestBody CompanyCardInDTO inDTO) {
        List<BossCompanyCard> bossCompanyCards = companyCardService.listAndPage(inDTO.getCompanyName(), inDTO.getStart(), inDTO.getLength());
        inDTO.setData(bossCompanyCards);
        long count = companyCardService.countByCondition(inDTO.getCompanyName());
        inDTO.setRecordsTotal(count);
        return inDTO;
    }


    @ResponseBody
    @RequestMapping("/update/status")
    public ResponseResult<String> updateStatus(@RequestBody CompanyCardInDTO inDTO) {
        BossCompanyCard card = new BossCompanyCard();
        card.setId(inDTO.getId());
        card.setStatus(inDTO.getStatus());
        companyCardService.updateById(card);
        return ResponseResult.success();
    }

    @RequestMapping("/detail")
    public String detail(Long id, Model model) {
        BossCompanyCard companyCard = companyCardService.getById(id);
        model.addAttribute("detail", companyCard);
        return "/company_card/detail";
    }


}
